// 引入路由组件
import Home from "@/pages/Home";
import Search from "@/pages/Search";
import Login from "@/pages/Login";
import Register from "@/pages/Register";
import Detail from "@/pages/Detail";
import AddCartSuccess from "@/pages/AddCartSuccess";
import ShopCart from "@/pages/ShopCart";
import Trade from "@/pages/Trade";
import Pay from "@/pages/Pay";
import PaySuccess from "@/pages/PaySuccess";
import Center from "@/pages/Center";
// 引入子路由
import MyOrder from "@/pages/Center/MyOrder";
import GroupOrder from "@/pages/Center/GroupOrder";


export default
[
  {
    path: '/home',
    name: 'home',
    component: Home,
    meta: {
      show: true,
    },
  },
  {
    path: '/search/:keyword?',
    name: 'search',
    component: Search,
    meta: {
      show: true,
    },
    // 路由组件能不能传props数据？
    // 布尔值写法：params
    // props: true,
    // 对象写法:额外给路由组件传递一些props
    // props: { a: 1, b: 2 },
    // 函数写法：可以params参数、query参数、通过props传递给路由组件
    // props: ($route) => ({
    //   return{ keywords: $route.params.keywords,
    //   keywords: $route.query.keywords,}
    // }),

  },
  {
    path: '/login',
    name: 'login',
    component: Login,
    meta: {
      show: false,
    },
  },
  {
    path: '/register',
    name: 'register',
    component: Register,
    meta: {
      show: false,
    },
  },
  {
    path: '/detail/:skuId',
    component: Detail,
    name: 'detail',
    meta: {
      show: true,
    },
  },
  {
    path: '/addcartsuccess',
    name: 'addcartsuccess',
    component: AddCartSuccess,
    meta: {
      show: true,
    },
  },
  {
    path: '/shopcart',
    name: 'shopcart',
    component: ShopCart,
    meta: {
      show: true,
    },
  },
  {
    path: '/trade',
    name: 'trade',
    component: Trade,
    meta: {
      show: true,
    },
    beforeEnter: (to, from, next) => {
      if (from.path == '/shopcar') {
        next();
      } else {
        next(false);
      }
    },
  },
  {
    path: '/pay',
    name: 'pay',
    component: Pay,
    meta: {
      show: true,
    },
    beforeEnter: (to, from, next) => {
      if (from.path == '/trade') {
        next();
      } else {
        next(false);
      }
    },
  },
  {
    path: '/paysuccess',
    name: 'paysuccess',
    component: PaySuccess,
    meta: {
      show: true,
    },
    beforeEnter: (to, from, next) => {
      if (from.path == '/pay') {
        next();
      } else {
        next(false);
      }
    },
  },
  {
    path: '/center',
    // name: 'center',
    component: Center,
    meta: {
      show: true,
    },
    children: [
      {
        path: 'myorder',
        component: MyOrder,
      },
      {
        path: 'grouporder',
        component: GroupOrder,
      },
      {
        path: '/center',
        redirect: '/center/myorder',
      },
    ],
  },
  // 重定向：在项目跑起来的时候，访问，定向到首页
  {
    path: '/',
    redirect: '/home',
  },
]

